package com.ljx.funchat.user.service.adatper;

import com.ljx.funchat.user.domain.entity.UserApply;
import com.ljx.funchat.user.domain.enums.UserApplyReadEnum;
import com.ljx.funchat.user.domain.enums.UserApplyStatusEnum;
import com.ljx.funchat.user.domain.vo.req.UserFriendApplyReq;
import com.ljx.funchat.user.domain.vo.resp.UserApplyResp;
import com.ljx.funchat.websocket.domain.vo.resp.WSApplyResp;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class UserApplyAdapter {
    public static UserApply buildApplySave(Long uid, UserFriendApplyReq req) {
        UserApply insert = new UserApply();
        insert.setMsg(req.getMsg());
        insert.setTargetId(req.getUid());
        insert.setUid(uid);
        insert.setType(req.getType());
        insert.setReadStatus(UserApplyReadEnum.NO_READ.getStatus());
        insert.setStatus(UserApplyStatusEnum.WAIT.getStatus());
        insert.setCreateTime(new Date());
        return insert;
    }

    public static List<UserApplyResp> buildApplyResp(List<UserApply> list) {
        return list.stream().map(item -> {
            UserApplyResp userApplyResp = new UserApplyResp();
            userApplyResp.setId(item.getId());
            userApplyResp.setUid(item.getUid());
            userApplyResp.setType(item.getType());
            userApplyResp.setMsg(item.getMsg());
            userApplyResp.setStatus(item.getStatus());
            return userApplyResp;
        }).collect(Collectors.toList());
    }

    public static WSApplyResp buildApplyWsResp(UserApply userApply, Integer unReadCount) {
        WSApplyResp wsApplyResp = new WSApplyResp();
        wsApplyResp.setUid(userApply.getUid());
        wsApplyResp.setMsg(userApply.getMsg());
        wsApplyResp.setUnRead(unReadCount);
        wsApplyResp.setType(userApply.getType());
        wsApplyResp.setTime(userApply.getCreateTime());
        return wsApplyResp;
    }
}
